from django.db import models
from mbook.models import Book
from django.contrib.auth.models import User

DEPS = (
	('A', 'CEO/CTO'),
	('B', 'DEV'),
	('C', 'OTHERS'),
)

class BookProfile(models.Model):
    '''Book status and manager'''
    book = models.OneToOneField(Book)
    num_available = models.IntegerField()
    num_reserving = models.IntegerField()
    num_total = models.IntegerField()
	
    def __unicode__(self):
        return self.book.title

    def is_available(self):
        return bool(self.num_available)
    def get_status(self):
        return self.num_available, self.num_total, self.num_reserving

class UserProfile(models.Model):
	user = models.OneToOneField(User)
	department = models.CharField(max_length=1, choices=DEPS)
	books = models.ManyToManyField(BookProfile, through='Reading')
	
	def __unicode__(self):
		return self.user.username

class Reading(models.Model):
	user_profile = models.ForeignKey(UserProfile)
	book_profile = models.ForeignKey(BookProfile)
